﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Automobile.service.Model;
using Automobile.service.BLL;
namespace Automobile.service.UI
{
    public partial class Supplier_list : System.Web.UI.Page
    {
        SupplierBLL bll = new SupplierBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Label1.Text = bll.GetCountSupplier().ToString();
                Login();
            }
        }
        /// <summary>
        /// 加载供货商信息
        /// </summary>
        private void Login()
        {
            Repeater1.DataSource = bll.ShowSupplier();
            Repeater1.DataBind();
        }

        protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            string ename = e.CommandName;//获取当前要执行的命令
            string id =e.CommandArgument.ToString();
            switch(ename)
            {
                case "del": 
                    if(bll.DelSupplier(id)>0)
                    {
                        JournalBLL jbll = new JournalBLL();
                        jbll.AddJourna_DelSupplier(Convert.ToInt32(Session["empid"]),id);
                        Response.Write("<script>alert('删除成功')</script>");
                        Login();
                    }
                    break;
                case "upt":
                    Response.Redirect("mem-alter.aspx?id="+id);
                    break;
            }
        }
        protected void Unnamed_ServerClick(object sender, EventArgs e)
        {
            string Supplier_name = Request.Form["Supplier_name"].ToString();
            Repeater1.DataSource = bll.SearchSupplier(Supplier_name);
            Repeater1.DataBind();
        }
    }
}